<template>
  <div class="reg_body">
      <van-nav-bar
          title="登录"
          left-text="返回"
          right-text="按钮"
          @click-left="leftClick"
          left-arrow
      />
      <h1>登录</h1>
      <div class="reg_wrap">
         <van-field v-model="userName"  placeholder="请输入用户名" />
        <van-field v-model="userPwd"  placeholder="请输入密码" />
        <van-button type="primary" @click="login">登录</van-button>
      </div>
    <div class="bottom_wrap">
       <a href="javascript:void(0);">忘记密码？</a>
       <a href="javascript:void(0);" @click="turnReg">快速注册</a>
    </div>
  </div>
</template>
<script>
import {LoginApi} from '../api/com'
export default {
  data(){
    return{
      userName:"",
      userPwd:""
    }
  },
  methods: {
    leftClick(){
      this.$router.go(-1)
    },
    turnReg(){
      this.$router.push("/reg")
    },
    // 登录方法
    async login(){
        var res=await LoginApi({
           userName:this.userName,
           userPwd:this.userPwd
        })
        console.log(res);
        if(res.err){
          this.$message.fail(res.err)
        }else{
          this.userName="";
          this.userPwd="";
          this.$message.success("登录成功");
        // 存储用户名到localStorage 
          localStorage.userName=res.data.name;
          this.$router.push("/mine");
        }
    }
  },
}
</script>
<style lang="less" scoped>
.reg_body{
  height: 100vh;
  background: url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202002%2F13%2F20200213014612_2Xkc3.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1647133579&t=60a12511589e05f83400c2971731fc3d);
}
h1{
  line-height: 100px;
  padding-left: 30px;
  box-sizing: border-box;
  color: white;
}
  .reg_wrap {
      height: 200px;
      display: flex;
      justify-content: space-around;
      flex-direction: column;
      .van-cell{
        width: 80%;
        margin: 0 auto;
      }
      .van-button{
        width: 50%;
        margin: 0 auto;
      }
  }
  .bottom_wrap{
    width: 100%;
    display: flex;
    margin: 10px auto;
    justify-content: space-around;
    font-size: 14px;
  }
</style>